package com.le.tester.imooc.oldfairy.coding.datastructure;

import java.util.Stack;

/**
 * createTime：2023/5/29 16:32
 * description：match
 */
public class Bracket {

    //使用栈实现括号匹配
    public boolean isMatch(String str) {

        Stack<Character> stack = new Stack<>();

        for (char c : str.toCharArray()) {
            if (c == '{') {
                stack.push(c);
            }
            if (c == '}') {
                if (stack.size() == 0) {
                    return false;
                }
                Character item = stack.pop();
                if (item != '{') {
                    return false;
                }
            }
        }
        return stack.size() == 0;

    }
}

